package com.culturalCenter.dataCenter.service.impl.activity;

import cn.hutool.core.collection.CollectionUtil;
import com.culturalCenter.dataCenter.Utils.DateFormatUtil;
import com.culturalCenter.dataCenter.customEntity.activity.CustomActivityException;
import com.culturalCenter.dataCenter.customEntity.activity.CustomActivityMonitorPersonList;
import com.culturalCenter.dataCenter.customEntity.activity.CustomActivitySiteMonitor;
import com.culturalCenter.dataCenter.customEntity.responseParam.activity.ActivitySiteMonitorResponse;
import com.culturalCenter.dataCenter.entity.activity.ActivityMonitorPersonnel;
import com.culturalCenter.dataCenter.entity.activity.ActivitySiteMonitorCount;
import com.culturalCenter.dataCenter.mapper.activity.ActivityMonitorPersonnelMapper;
import com.culturalCenter.dataCenter.mapper.activity.ActivitySiteMonitorCountMapper;
import com.culturalCenter.dataCenter.mapper.activity.ActivitySiteMonitorMapper;
import com.culturalCenter.dataCenter.service.activity.ActivitySiteMonitorService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author : weicai
 * @date : 14:26 2020/11/5
 */
@Service
public class ActivitySiteMonitorServiceImpl implements ActivitySiteMonitorService {

    @Resource
    private ActivitySiteMonitorCountMapper activitySiteMonitorCountMapper;
    @Resource
    private ActivityMonitorPersonnelMapper activityMonitorPersonnelMapper;
    @Resource
    private ActivitySiteMonitorMapper activitySiteMonitorMapper;

    @Override
    public ActivitySiteMonitorResponse getSiteMonitor(String activityId, int pageNum, int pageSize) {
        ActivitySiteMonitorResponse activitySiteMonitorResponse = new ActivitySiteMonitorResponse();
        // 当天人流情况曲线图
        List<ActivitySiteMonitorCount> crowdList = activitySiteMonitorCountMapper.queryByActivityId(activityId, DateFormatUtil.format(new Date()));
        if (CollectionUtil.isNotEmpty(crowdList)) {
            activitySiteMonitorResponse.setCrowdList(crowdList);
        }
        // 分页查询出入人员信息列表（不包括图片）
        PageHelper.startPage(pageNum, pageSize);
        List<CustomActivityMonitorPersonList> attendanceList = activityMonitorPersonnelMapper.queryByActivityId(activityId);
        attendanceList.forEach(w -> {
            if (w.getSource().equals("1")) {
                w.setSource("签到机");
            }
            if (w.getSource().equals("2")) {
                w.setSource("微信定位");
            }
            if (w.getSource().equals("3")) {
                w.setSource("手持扫码设备");
            }
            if (w.getSource().equals("4")) {
                w.setSource("后台");
            }
            if (w.getSource().equals("5")) {
                w.setSource("打印门票");
            }
        });
        PageInfo<CustomActivityMonitorPersonList> pageInfo = new PageInfo<>(attendanceList);
        activitySiteMonitorResponse.setAttendanceList(pageInfo);
        // 监控视频和照片
        List<CustomActivitySiteMonitor> monitorPictureListList = activitySiteMonitorMapper.queryVideoAndPicture(activityId);
        if (CollectionUtils.isNotEmpty(monitorPictureListList)) {
            activitySiteMonitorResponse.setMonitorPictureList(monitorPictureListList);
        }

        //分页查询现场异常情况
       /* List<CustomActivityException> exceptionList = activitySiteMonitorMapper.queryExceptionByActivityId(activityId);
        if (CollectionUtils.isNotEmpty(exceptionList)) {
            PageInfo<CustomActivityException> pageInfoException = new PageInfo<>(exceptionList);
            activitySiteMonitorResponse.setExceptionList(pageInfoException);
        }*/

        return activitySiteMonitorResponse;
    }

    @Override
    public PageInfo<CustomActivityException> getException(String activityId, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<CustomActivityException> activityExceptions = activitySiteMonitorMapper.queryExceptionByActivityId(activityId);
        return new PageInfo<>(activityExceptions);
    }

    @Override
    public List<ActivityMonitorPersonnel> getPersonMonitorPicture(String activityId, String userId) {
        return activityMonitorPersonnelMapper.getMonitorPicture(activityId, userId);
    }

}
